public class demon1 {
    private static Object o1=new Object();
    private static Object o2=new Object();
    private static Object o3=new Object();
    public static void main(String[] args) throws InterruptedException {
        Thread thread1=new Thread(()->{
            for (int i = 0; i < 10; i++) {
                synchronized (o3){
                    try {
                        o3.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                System.out.print("A");
                synchronized (o1){
                    o1.notify();
                }
            }
        });
        Thread thread2=new Thread(()->{
            for (int i = 0; i < 10; i++) {
                synchronized (o1){
                    try {
                        o1.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.print("B");
                    synchronized (o2){
                        o2.notify();
                    }
                }
            }
        });
        Thread thread3=new Thread(()->{
            for (int i = 0; i < 10; i++) {
                synchronized (o2){
                    try {
                        o2.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.println("C");
                }
                synchronized (o3){
                    o3.notify();
                }
            }
        });
        thread1.start();
        thread2.start();
        thread3.start();
        Thread.sleep(100);
        synchronized (o3){
            o3.notify();
        }
    }
}
